<?php /*a:2:{s:52:"D:\www\file\application\admin\view\role\setauth.html";i:1594695220;s:44:"D:\www\file\application\admin\view\head.html";i:1594631112;}*/ ?>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>后台登录-X-admin2.2</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/admin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        // 是否开启刷新记忆tab功能
        // var is_remember = false;
    </script>
</head>



  <body>
    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-form-item">
                现在正在为<span class="x-red"><?php echo htmlentities($data['role_name']); ?></span>分配权限
            </div>
            <form class="layui-form layui-form-pane">
                <input type="hidden" name=" role_id" value="<?php echo htmlentities($data['id']); ?>">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        拥有权限
                    </label>

                    <table  class="layui-table layui-input-block" style="width: 100%">

                        <tbody>
                        <?php foreach($top_auth as $top_v): ?>

                            <tr>
                                <td style="width: 10%">
                                    <input class="top_auth" type="checkbox" lay-filter="top_auth" name="id[]"  lay-skin="primary"  value="<?php echo htmlentities($top_v['id']); ?>" <?php if(in_array(($top_v['id']), is_array($data['role_auth_ids'])?$data['role_auth_ids']:explode(',',$data['role_auth_ids']))): ?> checked="checked"<?php endif; ?> ><?php echo htmlentities($top_v['auth_name']); ?>

                                </td>
                                <td style="width: 90%">
                                    <div class="layui-input-block">
                                        <?php foreach($second_auth as $second_v): if(($second_v['pid'] == $top_v['id'])): ?>


                                        <input class="second_auth" name="id[]" lay-skin="primary" lay-filter="second_auth" type="checkbox"  value="<?php echo htmlentities($second_v['id']); ?>" <?php if(in_array(($second_v['id']), is_array($data['role_auth_ids'])?$data['role_auth_ids']:explode(',',$data['role_auth_ids']))): ?> checked="checked" <?php endif; ?> > <?php echo htmlentities($second_v['auth_name']); ?>


                                        <?php endif; ?>
                                        <?php endforeach; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>

                <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add">修改</button>
              </div>
            </form>
        </div>
    </div>


    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          form.on('checkbox(top_auth)',function (data) {
              var status = $(this).prop('checked');

              $(this).parent().siblings('td').find('.second_auth').prop('checked',status);
              form.render();
              //$(this).closest('td').find('.second_auth').prop('checked',status)
              
          });

            //监听提交
            form.on('submit(add)', function(data) {
                $.ajax({
                    url: "<?php echo url('admin/role/saveauth'); ?>",
                    type:'post',
                    data:data.field,
                    success:function (callback) {
                        if (callback.msg == 200){
                            layer.msg('修改角色权限成功',{icon:6});
                            setTimeout(function () {
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            },1200);
                        }else {
                            layer.msg("修改角色权限失败", {icon: 6})
                        }

                    }
                });
                return false;
            });

        });
    </script>

  </body>
  <script>
      $(function () {
          //顶级权限 选中效果


         // $(".top_auth").click(function () {

              //  console.log(index)
              //var status = $(this).prop('checked');
              // console.log(status);

              //将当前行权限 设置为顶级权限状态一直
              // $(this).closest('td').find('.second_auth').prop('checked',status)
         // });
          //二级权限
          $('.second_auth').change(function () {
              var checked = $(this).closest('td').find('.second_auth:checked');
              var status = checked.length>0;
              $(this).closest('td').find('.top_auth').prop('checked',status);
          });
      });

  </script>

